home *** CD-ROM | disk | FTP | other *** search
Wrap
/* gxStyle Layout Sample Program By Eric Mader, After Mike Fairman, Oliver Steele et. al. 1.0B2 (MD, 09/10/93) -- allocate a new 1 MB graphics client instead of using the default 600K client. */ /* Copyright ©1989, 1990, 1991 Apple Computer, Inc. All rights reserved. */ #ifndef THINK_C #include <Quickdraw.h> #include <Fonts.h> #include <Windows.h> #include <Dialogs.h> #include <Events.h> #include <Memory.h> #include <Menus.h> #include <String.h> #include <Desk.h> #include <Script.h> #include <ToolUtils.h> #define thePort qd.thePort #define screenBits qd.screenBits #endif #include "graphics libraries.h" #include "qd library.h" #include "font library.h" #include "graphics debugging.h" #include "graphics routines.h" #include "graphics toolbox.h" #include "layout feature constants.h" #include "layout types.h" #include "layout routines.h" #include "layout library.h" /* This macro is useful for constructing fixed values */ #define f(a,b) (((fixed) (a) << 16) + (b)) /* various menu and dialog things */ enum {aboutDLOG = 128, appleMenuID = 128, fileMenuID, editMenuID}; /* resource ID's */ enum {okButton = 1, showsItem, authorItem}; enum { /* Apple Menu */ aboutCommand = 1, /* File Menu */ quitCommand = 1, /* Edit Menu */ undoCommand = 1, cutCommand, copyCommand, pasteCommand, clearCommand}; WindowPtr myWindow, whichWindow; gxViewPort myPort; Rect qdWindowRect; Rect growRect = {40, 40, 32767, 32767}; Rect bigRect = {-32768, -32768, 32767, 32767}; gxRectangle windowRect; MenuHandle appleMenu, fileMenu, editMenu; Boolean done = false; gxColor colorWhite = xRGB (0xFFFF, 0xFFFF, 0xFFFF); /* white */ gxColor hsvInitial = xHSV (0, 0xFFFF, 0xFFFF); /* red */ static void ShowAboutBox () { GrafPtr savePort; DialogPtr theDialog; short itemType; Handle itemHdl; Rect itemRect; short itemHit; GetPort(&savePort); theDialog = GetNewDialog(aboutDLOG, nil, (WindowPtr) -1); SetPort(theDialog); GetDItem(theDialog, authorItem, &itemType, &itemHdl, &itemRect); SetIText(itemHdl, (unsigned char *) "\pRice Dream"); GetDItem(theDialog, showsItem, &itemType, &itemHdl, &itemRect); SetIText(itemHdl, (unsigned char *) "\pText gxStyle Changes"); do { ModalDialog(nil, &itemHit); } while (itemHit != okButton); CloseDialog(theDialog); SetPort(savePort); } static void SetupMenus () { InsertMenu (appleMenu = GetMenu (appleMenuID), 0); AddResMenu (appleMenu, (ResType) 'DRVR'); InsertMenu (fileMenu = GetMenu (fileMenuID), 0); InsertMenu (editMenu = GetMenu (editMenuID), 0); DrawMenuBar (); } static void DoMenuCommand (long mResult) { short theItem = LoWord (mResult), theMenuID = HiWord (mResult); GrafPtr savePort; Str255 daName; switch (theMenuID) { case appleMenuID: if (theItem == aboutCommand) ShowAboutBox (); else { GetItem (appleMenu, theItem, daName); GetPort (&savePort); (void) OpenDeskAcc (daName); SetPort (savePort); } break; case fileMenuID: if (theItem == quitCommand) done = true; break; case editMenuID: break; } HiliteMenu (0); } static short StrLength(char *s) {short len; for (len = 0; *s++ != 0; len++) ; return len; } void main() { EventRecord theEvent; gxShape layout, whiteOut; gxRunControls gxRunControls, testControls; gxLayoutOptions gxLayoutOptions; gxStyle glyphStyles[3]; char *text1 = "Aetna "; /* The following is "Arabic Macintosh" in Arabic: */ /* meem, alif, kaf, noon, tah, wau, shin, */ /* <sp>, alif, lam, ein, reh, beh, yeh */ static char text2[] = {0xE5, 0xC7, 0xE3, 0xE6, 0xCA, 0xE8, 0xD4, 0x20, 0xC7, 0xE4, 0xD9, 0xD1, 0xC8, 0xEA, 0}; char *text3 = " Office AWAY."; char *textRuns[3]; short level0, textLengths[3], totalLength; gxPoint posn; GDHandle max; short mbh = GetMBarHeight (); gxGraphicsClient ourClient; MaxApplZone(); MoreMasters(); MoreMasters(); ourClient = GXNewGraphicsClient(0L, 1024 * 1024, 0L); if (ourClient != NULL) { SetGraphicsLibraryErrors(); SetGraphicsLibraryNotices (); /*GXSetValidation(gxInternalValidation | gxStructureValidation | gxNoMemoryManagerValidation); /* uncomment this for less speed and more error-checking */ InitCommonColors (); InitGraf(&thePort); InitFonts(); InitWindows(); InitMenus (); InitCursor(); SetupMenus (); /* find the deepest monitor, and make a window that just covers it */ max = GetMaxDevice (&bigRect); qdWindowRect = (**max).gdRect; /* bring it down one mbh for the header, maybe another if on main screen */ if (qdWindowRect.top == 0 && qdWindowRect.left == 0) qdWindowRect.top += mbh; qdWindowRect.top += mbh; InsetRect (&qdWindowRect, 4, 4); ShortRectToFixed (&qdWindowRect, &windowRect); myWindow = NewWindow(nil, &qdWindowRect, (unsigned char *) "\pStyle Layout Sample", true, documentProc, (WindowPtr) -1L, true, 0L); myPort = GXNewWindowViewPort (myWindow); SetDefaultViewPort (myPort); /* When we want to erase the whole window, we just GXDrawShape (whiteOut). */ whiteOut = GXNewShape (gxFullType); GXSetShapeColor (whiteOut, &colorWhite); /* gxInitialize the textRuns array */ textRuns[0] = text1; textRuns[1] = text2; textRuns[2] = text3; /* gxInitialize the textLengths array */ textLengths[0] = StrLength (text1); textLengths[1] = StrLength (text2); textLengths[2] = StrLength (text3); totalLength = textLengths[0] + textLengths[1] + textLengths[2]; /* Make a default gxLayoutOptions and gxRunControls */ InitializeLayoutOptions (&gxLayoutOptions); InitializeRunControls (&gxRunControls); InitializeRunControls (&testControls); /* Position the layout half way down the left edge of the window. Set the layout's width to the window's width and set the flushness to 1/2, this will cause the layout to center in the window. */ gxLayoutOptions.width = windowRect.right - windowRect.left; gxLayoutOptions.flush = fract1/2; posn.x = 0; posn.y = (windowRect.bottom - windowRect.top) / 2; /* run 0 is 38 pt. Helvetica */ glyphStyles[0] = NewLayoutStyle((char *) "\pHelvetica", ff(38), 0, &gxRunControls, nil, 0, nil); /* SetStyleCommonFace (glyphStyles[0], italic); */ /* run 1 is 38 pt. Baghdad (Arabic) */ glyphStyles[1] = NewLayoutStyle((char *) "\pBaghdad Plain", ff(38), 0, &gxRunControls, nil, 0, nil); /* run 2 is 38 pt. Times */ glyphStyles[2] = NewLayoutStyle((char *) "\pTimes Roman", ff(38), 0, &testControls, nil, 0, nil); /* Build the layout. */ layout = GXNewLayout( 3, textLengths, (void *) textRuns, 3, textLengths, glyphStyles, 1, &totalLength, &level0, &gxLayoutOptions, &posn); GXCacheShape(layout); testControls.flags |= gxImposeRightToLeft; GXSetStyleRunControls(glyphStyles[2], &testControls); GXDrawShape (layout); /* Now just spin in a simple event loop until it's time to go */ while (!done) { if (WaitNextEvent(everyEvent, &theEvent, 0, nil)) { switch(theEvent.what) { case mouseDown: switch (FindWindow(theEvent.where, &whichWindow)) { case inSysWindow: SystemClick(&theEvent, whichWindow); break; case inMenuBar: DoMenuCommand (MenuSelect (theEvent.where)); break; case inDrag: DragWindow(whichWindow, theEvent.where, &screenBits.bounds); break; case inGrow: { register long newSize; newSize = GrowWindow(whichWindow, theEvent.where, &growRect); SizeWindow(whichWindow, LoWord(newSize), HiWord(newSize), true); } break; case inGoAway: if (TrackGoAway(whichWindow, theEvent.where)) done = true; break; case inContent: if (whichWindow != FrontWindow()) SelectWindow(whichWindow); break; } break; case keyDown: case autoKey: if (myWindow == FrontWindow () && theEvent.modifiers & cmdKey) DoMenuCommand (MenuKey (theEvent.message & charCodeMask)); break; case updateEvt: BeginUpdate((WindowPtr)theEvent.message); GXDrawShape (whiteOut); testControls.flags &= ~gxDirectionOverrideMask; GXSetStyleRunControls(glyphStyles[2], &testControls); GXCacheShape(layout); testControls.flags |= gxImposeRightToLeft; GXSetStyleRunControls(glyphStyles[2], &testControls); GXDrawShape (layout); EndUpdate((WindowPtr)theEvent.message); break; } } } /* dispose everything we've allocated. */ GXDisposeShape(layout); GXDisposeStyle (glyphStyles[0]); GXDisposeStyle (glyphStyles[1]); GXDisposeStyle (glyphStyles[2]); DisposeWindow(myWindow); GXDisposeShape (whiteOut); DisposeCommonColors (); GXDisposeGraphicsClient(ourClient); } }